package com.eliauk.demo.utils.excel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class UsernameConverter implements Converter<String> {

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return Converter.super.supportExcelTypeKey();
    }

    @Override
    public Class<?> supportJavaTypeKey() {
        return Converter.super.supportJavaTypeKey();
    }

    //Excel数据转Java数据其中cellData表示读出的单元格数据
    //现在你可以这个单元数据进行操作，因为实现的是字符串类型的Converter 所以返回值是String
    @Override
    public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String cellData_str = cellData.getStringValue();//把单元格数据转为字符串类型
        return "新用户--"+cellData_str;//返回拼接的字符串，
    }

    //从Java数据转到Excel数据重写的接口,最简单的就是不做转换直接返回
    @Override
    public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new WriteCellData<>(value);
    }
}
